from django.db.models import *


def get_dict(obj, fields=None, exclude=None):
    data = {}
    for f in obj._meta.concrete_fields + obj._meta.many_to_many:
        value = f.value_from_object(obj)
        if fields and f.name not in fields:
            continue
        if exclude and f.name in exclude:
            continue
        if isinstance(f, ManyToManyField):
            continue
        if isinstance(f, DateField):
            value = value.strftime('%Y-%m-%d') if value else None
        if isinstance(f, TimeField):
            value = value.strftime('%H:%M:%S') if value else None
        data[f.name] = value
    return data
